package org.example.models.abstracts;


import org.example.models.interfaces.Action;
import org.example.models.interfaces.observe.Observer;
import org.example.models.interfaces.own.Ownable;
import org.example.models.interfaces.own.Owner;

import java.util.ArrayList;
import java.util.List;

public abstract class AbstractLiving implements Observer, Owner {
    private String name;
    private int age;

    private final List<Ownable> ownables;

    public AbstractLiving(String name, int age, List<Ownable> ownables) {
        this.name = name;
        this.age = age;
        this.ownables = ownables;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) { this.age = age; }

    public <T extends AbstractLiving> void act(Action<T> action) {
        action.perform((T) this);
    }

    @Override
    public List<Ownable> getOwnables() {
        return ownables;
    }

    @Override
    public boolean addOwnable(Ownable ownable) {
        return ownables.add(ownable);
    }

    @Override
    public boolean removeOwnable(Ownable ownable) {
        return ownables.remove(ownable);
    }

    public void describeAction(String action) {
        System.out.println(this + " совершил " + action);
    }
}
